/**
 * Copyright 2018 orivil.com. All rights reserved.
 * Use of this source code is governed by a MIT-style
 * license that can be found at https://mit-license.org.
 */

package log

import (
	"log"
	"os"
	"io"
)

type flag int

const (
	INIT flag = 1 << iota
	INFO
	ERROR
	WARNING
	DANGER
	EMERGENCY

)

// Init 用于程序初始化时保存一些重要信息
var Init = log.New(os.Stdout, "", log.LstdFlags)

var Info = log.New(os.Stdout, "[Info]", log.LstdFlags)

var Warning = log.New(os.Stderr, "[Warning]", log.LstdFlags|log.Llongfile)

var Danger = log.New(os.Stderr, "[Danger]", log.LstdFlags|log.Llongfile)

var Error = log.New(os.Stderr, "[Error]", log.LstdFlags|log.Llongfile)

var Emergency = log.New(os.Stderr, "[Emergency]", log.LstdFlags|log.Llongfile)

func SetOutput(flag flag, writer io.Writer) {
	if flag & INIT != 0 {
		Init.SetOutput(writer)
	}
	if flag & INFO != 0 {
		Info.SetOutput(writer)
	}
	if flag & WARNING != 0 {
		Warning.SetOutput(writer)
	}
	if flag & ERROR != 0 {
		Error.SetOutput(writer)
	}
	if flag & DANGER != 0 {
		Danger.SetOutput(writer)
	}
	if flag & EMERGENCY != 0 {
		Emergency.SetOutput(writer)
	}
}